package com.zhiyou100.loans.service.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.mysql.jdbc.ResultSetRow;
import com.zhiyou100.loans.dao.LendbillDao;
import com.zhiyou100.loans.dao.impl.LendbillDaoImpl;
import com.zhiyou100.loans.model.Lendbill;
import com.zhiyou100.loans.model.Result;
import com.zhiyou100.loans.service.LendbillService;
import com.zhiyou100.loans.util.NetDate;

import net.sf.json.JSONObject;

public class LendbillServiceImpl implements LendbillService {
	LendbillDao lendd = new LendbillDaoImpl();

	@Override
	public JSONObject add(Lendbill lendbill) {
		lendbill.setLendtime(NetDate.getCurrentTime());
		Result result = new Result(false, "出借失败");
		int i = lendd.add(lendbill);
		if(i>0){
			result.setFlag(true);
			result.setMessage("出借成功");
		}
		return JSONObject.fromObject(result);
	}

	@Override
	public JSONObject selectTotalLendmoney(String lenderid) {
		ResultSet rs = lendd.selectTotalLendmoney(Integer.parseInt(lenderid));
		Lendbill ldb = null;
		try {
			if(rs.next()){
				ldb = new Lendbill();
				ldb.setMoney(rs.getDouble("money"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return JSONObject.fromObject(ldb);
	}

}
